		include	Common.asm

; ----------------------------------------------------------
Stack		segment para stack 'stack'
	dw	256 dup(0)
Stack		ends

; ----------------------------------------------------------
DataSeg		segment para public 'data'
		PcxFile		db	"Resource.pcx"
		TestText	db	"Babo Innover I am Hungry", 0
DataSeg		ends

; ----------------------------------------------------------
CodeSeg		segment para public 'code'
		assume	cs: CodeSeg, ds: DataSeg, ss: Stack

Main		proc
	mov	ax, DataSeg
	mov	ds, ax

	; Set Video mode - Graphic Mode
	mov	ah, 0h		; ah = 0h - Set Video mode
	mov	al, 13h		; al = 13h - 320x200x256
	int	10h

	; ----------------------------------------------------------
	; LoadPCX: Load PCX File
	; ----------------------------------------------------------
	mov	ax, 08000h	; Resource Buffer
	mov	es, ax
	lea	bx, PcxFile
	call	LoadPCX
	
MainLoop:
	; Fill Rect
	mov	bx, 0
	push	bx
	push	bx
	mov	bx, GraphScreenWidth
	push	bx
	mov	bx, GraphScreenHeight
	push	bx
	mov	bx, 0
	push	bx
	call	FillRect


	; Draw Boxed Text
	mov	al, 10001000B	; Align(left top)
	mov	ah, 0cch	; Color
	mov	cx, -25h	; X
	mov	dx, -05h	; Y
	call	DrawBoxedText

	mov	al, 10001000B	; Align(left top)
	mov	ah, 0ddh	; Color
	mov	cx, 0d0h	; X
	mov	dx, 16h		; Y
	call	DrawBoxedText

	mov	al, 10001000B	; Align(left top)
	mov	ah, 0eeh	; Color
	mov	cx, 20h		; X
	mov	dx, 9dh		; Y
	call	DrawBoxedText

	mov	al, 00100010B	; Align(center middle)
	mov	ah, 44h		; Color
	mov	cx, -65h	; X
	mov	dx, 16h		; Y
	call	DrawBoxedText

	mov	al, 00100010B	; Align(center middle)
	mov	ah, 55h		; Color
	mov	cx, 15h		; X
	mov	dx, 31h		; Y
	call	DrawBoxedText

	mov	al, 00100010B	; Align(center middle)
	mov	ah, 66h		; Color
	mov	cx, 80h		; X
	mov	dx, 4ch		; Y
	call	DrawBoxedText

	mov	al, 00100010B	; Align(center middle)
	mov	ah, 77h		; Color
	mov	cx, 80h		; X
	mov	dx, 0b8h	; Y
	call	DrawBoxedText

	mov	al, 01000100B	; Align(right buttom)
	mov	ah, 88h		; Color
	mov	cx, -85h	; X
	mov	dx, 4ch		; Y
	call	DrawBoxedText

	mov	al, 01000100B	; Align(right buttom)
	mov	ah, 99h		; Color
	mov	cx, 20h		; X
	mov	dx, 67h		; Y
	call	DrawBoxedText

	mov	al, 01000100B	; Align(right buttom)
	mov	ah, 0aah	; Color
	mov	cx, 80h		; X
	mov	dx, 82h		; Y
	call	DrawBoxedText

	mov	al, 01000100B	; Align(right buttom)
	mov	ah, 0bbh	; Color
	mov	cx, -86h	; X
	mov	dx, 0b8h	; Y
	call	DrawBoxedText

	lea	ax, TestText
	push	ax			; text
	mov	ax, 0
	push	ax			; x
	push	ax			; y
	mov	ax, 100h
	push	ax			; x
	mov	ax, 18h
	push	ax			; y
	mov	al, 00100010B		; Align(center middle)
	mov	ah, 7		; Color
	push	ax			; Align and COlor
	call	DrawText	

	call	Present

	call	ChkKeyInput
	cmp	al, 1h
	je	MainLoop

											; ----------------------------------------------------------
											; ResourceChk
											;	al: Line Color
											;	es: Target Address
											; ----------------------------------------------------------
											;mov	ax, 08000h	; Resource Buffer
											;mov	es, ax
											;mov	ax, 002dh
											;call	ResourceChk

	mov	ah, 0h		; ah = 0 - Read char from buffer, wait if empty
	int	16h		;

	; Set Video mode - Text Mode
	mov	ah, 0h		; ah = 0h - Set Video mode
	mov	al, 3h		; al = 3h - Text Mode
	int	10h

	; Terminate program
	mov	ax, 4c00h	; ah = 4ch - Terminate program, al = Exit code
	int	21h
Main		endp

; ----------------------------------------------------------
; Check Keyboard input
; [Return]	al: 0 - character in buffer
;		al: 1 - no character in buffer
; ----------------------------------------------------------
ChkKeyInput	proc	near
		mov	ah, 1h		; ah = 1 - Keyboard: Check buffer, do not clear
		int	16h		; [Check] ZF = 0, character in buffer
		mov	al, 0h
		jnz	ChkKeyInputRet	; jump to ChkKeyInputRet, if ZF = 0
		mov	al, 1h		
ChkKeyInputRet:
		ret
ChkKeyInput	endp

; ----------------------------------------------------------
; Draw Boxed Text
; Input:
;	ax: Color / Align
;	cx: pos x
;	dx: pox y
; ----------------------------------------------------------
DrawBoxedText	proc	near
	push	cx
	push	dx
	mov	bx, 100h
	push	bx
	mov	bx, 18h
	push	bx
	mov	bx, 0ah
	push	bx
	call	FillRect

	lea	bx, TestText	; Text Address
	push	bx
	push	cx
	push	dx
	mov	bx, 100h	; sizeX position
	push	bx
	mov	bx, 18h		; sizeY position
	push	bx
	push	ax
	call	DrawText
	ret
DrawBoxedText	endp

CodeSeg		ends

		end	Main

